from GBDTModel import GBDTModel
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
from pandas import DataFrame
from scipy.interpolate import make_interp_spline

sns.set()


def main():
    dataset = pd.read_excel('../../data/newData.xlsx')
    # 要分析的数据
    X = dataset.iloc[5:, 1:360].values

    print("======原始数据的形状========")
    print(np.array(X).shape)
    # print(X)

    # 转置
    X_index = [[row[i] for row in X] for i in range(len(X[0]))]
    X_index = np.array(X_index)

    # 输入数据
    x = np.array(X_index)
    print(np.array(x).shape)
    print(x)
    print("===============")
    print(x[0][150])

    # 求出预测q
    model = GBDTModel
    x = np.array(x)
    print("============模型预测=============")
    q_predict = get_q_layer_high(x)
    print("q预测结果：%s" % (q_predict))
    predict = q_predict
    # 转q
    q_location = []
    for i in predict:
        value = (int)(round(360 - (i - 0.6) / 0.05 ))
        q_location.append(value)
    print(q_location)
    print("=================")
    print("qqqqq:%s"%(q_location[0]))
    # 找温度
    q_temperature=[]
    for i in range(108):
        q_temperature.append(x[i][q_location[i]])
    print(q_temperature)
    # 数组放大四倍
    df = DataFrame(q_temperature)
    df.to_excel('../../excelData/ding_chen_find_predict_temperature_help_from_me.xlsx')


def four_time_nums(num):
    length = len(num)
    result = []
    for i in num:
        for j in range(4):
            result.append(i)
    return result


# 获取q层高度
# input: 360*n  n组数据
# return  n组数据对应的第三层高度
def get_q_layer_high(input):
    # 模型
    model = GBDTModel
    print("==========X_index=============")
    print(np.array(input).shape[0])
    q_layer_high_num = np.array(range(np.array(input).shape[0]), dtype=float)
    for i in range(np.array(input).shape[0]):
        # 处理空值
        for j in range(360):
            if np.isnan(input[i][j]):
                input[i][j] = 0
        res = model.predict(model, input[i], name, index)
        print(f"{i + 1}预测值为：{res} ")

        q_layer_high_num[i] = res

    print("==========three_layer_high_num=============")
    print(np.array(q_layer_high_num).shape)
    # print(three_layer_high_num)
    return q_layer_high_num


index = 40
name = "../../data/q_"
num_of_index = 1
if __name__ == "__main__":
    main()
